export default{
	// 开启命名空间
	namespaced:true,
	// 数据
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address')||"{}"),
		
		token:'',
		// 存储用户信息
		userInfo:JSON.parse(uni.getStorageSync('userinfo') || "{}"),
		// address:{}
		// 用来记录页面跳转的方法和路径
		redirectInfo:null
	}),
	// 方法
	mutations:{
		// 更新收货地址
		updateAddress(state,address){
			state.address=address
			this.commit('m_user/saveAddressToStorage')
		},
		// 存address
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		// 更新用户信息
		updateUserInfo(state,userInfo){
			state.userInfo=userInfo
			this.commit('m_user/saveUserInfoToStorage')
		},
		// 存储用户信息
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userInfo))
		},
		updateToken(state,token){
			state.token=token
			this.commit('m_user/saveTokenToStorage')
		},
		saveTokenToStorage(state){
			uni.setStorageSync('token',JSON.stringify(state.token))
		},
		// 用来记录页面跳转的方法和路径的方法
		updateRedirectInfo(state,info){
			state.redirectInfo=info
			// console.log(state.redirectInfo)
		}
		
	},
	// getters相当于computed
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
			return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
		}
	}
}